import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import "/public/iconfont/iconfont.css";//阿里图标
import '@/router/dynamicAddRouter';//路由匹配
import { i18n } from "@/i18n";
import { useUserStore } from "@/stores/admin/Index";
import 'nprogress/nprogress.css'


const app = createApp(App)
const pinia = createPinia();
app.use(createPinia())
pinia.use(piniaPluginPersistedstate);

app.use(router)
app.use(pinia);
app.use(ElementPlus)
app.use(i18n)

app.mount('#app')

// 自定义指令
app.directive('permission', {
    mounted(el, binding) {
        const store = useUserStore()
        let val = binding.value
        var permissionList = store.permissionList || [] //[]防止空指针异常

        let obj = {}
        if (JSON.stringify(permissionList).indexOf("*") != -1) {
            permissionList.map((item, index) => {
                if ('*' == item) {
                    obj = item
                }
            })
        }

        if (obj != -1) {
            if (-1 == permissionList.indexOf(val)) {
                el.remove?.()
            }
        }
    }
})
